How can I extract values from a list in Python effectively